<!--
 * @Description: 项目入口文件
 * @Author: 0001100986/LiuShuai
 * @Date: 2021-06-22 14:09:49
 * @LastEditTime: 2021-09-28 15:55:43
 * @LastEditors: 0001100986/LiuShuai
-->
<template>
  <div id="app" @contextmenu.prevent>
    <router-view />
  </div>
</template>

<script>
import { getMenuList } from '@/api/menuApi.js';
import { pagePath } from '@/utils/monitor';

export default {
  name: 'App',
  created () {
    this.initState();
    this.getMenuList();
  },
  data () {
    return {};
  },
  watch: {
    '$route': function(to, from) {
      pagePath(to);
    }
  },
  methods: {
    // 初始化State
    initState () {
      let sys = JSON.parse(localStorage.getItem('sys'));
      if (sys) {
        if (sys.user.isLogin) {
          this.$store.dispatch('user/setUserInfo', {
            token: sys.user.token,
            user: sys.user.info
          });
          this.$store.dispatch('user/setLoginStatus', true);
        } else {
          this.$store.dispatch('user/initState');
        }
      }
      this.$store.dispatch('worktab/initState');
      this.$store.dispatch('setting/initState');
    },
    // 获取菜单列表
    getMenuList () {
      getMenuList();
    }
  }
};
</script>